package com.cw.jeeyt.service.converter.api;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.api.ApiFacadeModuleInfoBo;
import com.cw.jeeyt.dao.model.api.ApiFacadeModuleInfoDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * api接口文档所在项目模块转换类
 *
 * @author chenw
 * @date 2019-03-10 13:05:36
 */
public class ApiFacadeModuleInfoConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiFacadeModuleInfoBo do2Bo(ApiFacadeModuleInfoDo model) {
        if (model == null) {
            return null;
        }
        ApiFacadeModuleInfoBo bo = new ApiFacadeModuleInfoBo();
        bo.setId(model.getId());
        bo.setProjectId(model.getProjectId());
        bo.setModuleCode(model.getModuleCode());
        bo.setModuleName(model.getModuleName());
        bo.setModuleComment(model.getModuleComment());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiFacadeModuleInfoDo bo2Do(ApiFacadeModuleInfoBo bo) {
        if (bo == null) {
            return null;
        }
        ApiFacadeModuleInfoDo model = new ApiFacadeModuleInfoDo();
        model.setId(bo.getId());
        model.setProjectId(bo.getProjectId());
        model.setModuleCode(bo.getModuleCode());
        model.setModuleName(bo.getModuleName());
        model.setModuleComment(bo.getModuleComment());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiFacadeModuleInfoBo> doList2BoList(List<ApiFacadeModuleInfoDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiFacadeModuleInfoConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiFacadeModuleInfoDo> boList2DoList(List<ApiFacadeModuleInfoBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiFacadeModuleInfoConverter::bo2Do));
    }
}